﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace JiravaNet.Web.UI.Fieldset {

	/// <summary>
	/// <see cref="HtmlHelper"/> extension for input controls
	/// </summary>
	public static class HelperInputExtension {

		/// <summary>
		/// Creates an input element with type submit
		/// </summary>
		/// <param name="helper"><see cref="HtmlHelper"/></param>
		/// <param name="name">name of the element</param>
		/// <param name="text">text inside the element</param>
		/// <returns></returns>
		public static string Submit(this HtmlHelper helper, string name, string text) {
			return Submit(helper, name, text, null);
		}

		/// <summary>
		/// Creates an input element with type submit
		/// </summary>
		/// <param name="helper"><see cref="HtmlHelper"/></param>
		/// <param name="name">name of the element</param>
		/// <param name="text">text inside the element</param>
		/// <param name="htmlAttributes">additional html attributes</param>
		/// <returns></returns>
		public static string Submit(this HtmlHelper helper, string name, string text, IDictionary<string, object> htmlAttributes) {
			var builder = new TagBuilder("input");
			builder.MergeAttributes<string, object>(htmlAttributes);
			builder.MergeAttribute("type", "submit");
			builder.MergeAttribute("name", name);
			builder.MergeAttribute("value", text);
			return builder.ToString(TagRenderMode.SelfClosing);
		}
	}
}
